<?php

class MFormText extends MFormInput {
    const FORMAT_EMAIL = 'email';

    protected $_format;

    public function __construct($name, $form) {
        parent::__construct($name, $form);
        $this->setHtmlOption('type', 'text');
        if ($form->useFormee)
            $this->setHtmlOption('class', 'form-txt');
    }

    public function isValid($value) {
        $valid = parent::isValid($value);
        if (isset($this->_format)) {
            switch ($this->_format) {
                case self::FORMAT_EMAIL:
                    if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
                        $this->_form->addError(__t('mandrill.web.form.emailNotValid'));
                        $valid = false;
                    }
                    break;
                default:
                    break;
            }
        }
        return $valid;
    }

    public function getCleanedValue($value) {
        return parent::getCleanedValue(htmlspecialchars($value));
    }

    public function getFormat() {
        return $this->_format;
    }

    /**
     * Possible values : email
     * @param String $format
     */
    public function setFormat($format) {
        $this->_format = $_format;
    }

}

?>
